package com.uw.scenic.utils;
import java.io.*;
/**
 * 创建.java文件所在路径 和 返回.java文件File对象
 * @param outDirFile 生成文件路径
 * @param javaPackage java包名
 * @param javaClassName java类名
 * @return
 */
/**
 * 创建.java文件所在路径 和 返回.java文件File对象
 * @return
 */

public final class FileUtil {

    /**
     * 创建.java文件所在路径 和 返回.java文件File对象
     * @param outDirFile 生成文件路径
     * @param javaPackage java包名
     * @param javaClassName java类名
     * @return
     */
    public static File generateJavaFile(File outDirFile, String javaPackage, String javaClassName) {
        String packageSubPath = javaPackage.replace('.', '/');
        File packagePath = new File(outDirFile, packageSubPath);
        File file = new File(packagePath, javaClassName + ".java");
        if(!packagePath.exists()){
            packagePath.mkdirs();
        }
        return file;
    }


    public static File generateJavaFile(File outDirFile, String javaClassName) throws  Exception {
        javaClassName+=".java";
        File file = new File(outDirFile, javaClassName);
        if(!file.exists()){
            file.createNewFile();
        }
        return file;
    }

    public static void write(File file,String text) throws  Exception{
//        FileWriter writer=new FileWriter(file);
//        writer.write(text);
//        writer.close();
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
        writer.write(text);
        writer.close();
    }



}